// pages/centerCollect/centerCollect.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userCollect:[],
    shopcid:'',
    userid:'',

  },
  onLoad:function(){
    //获取用户id发送请求
    var userid = wx.getStorageSync("OoOoUserid");
    var data = {
      userid:userid,
    }
    var that = this;
    //获取收藏商品
    wx.request({
      url:'http://47.104.142.216/TP/public/index.php/index/Usercenter/selectCollect',
      dataType:'json',
      method:'POST',
      data:data,
      header:{
        'content-type':'application/x-www-form-urlencoded'
      },
      success:function(res){
          that.setData({
            //第一个data为固定用法
            userCollect: res.data
          })
        },
        fail:function(err){
        console.log(err)
        }
    });
  },
  //确认取消框
  cancelcollection:function(e){
    var that = this;
    this.setData({
      shopcid: e.currentTarget.dataset.shopid,
    })
    var newshopid = this.data.shopcid;
    wx.showModal({
      title: '提示',
      content: '确定取消收藏吗?',
      success (res) {
        if (res.confirm) {
          var userid = wx.getStorageSync("OoOoUserid");
          var data = {
            shopid : newshopid,
            userid : userid
          }
          //取消收藏
          wx.request({
            url:'http://47.104.142.216/TP/public/index.php/index/Usercenter/delCollectt',
            dataType:'json',
            method:'POST',
            data:data,
            header:{
              'content-type':'application/x-www-form-urlencoded'
            },
            success:function(res){
              if(res.data == 10000){
                  wx.showToast({
                    title: '取消成功',
                    icon: 'success',
                    duration: 2000
                  })
                  that.onLoad()
                  return;
              }
            },
              fail:function(err){
              console.log(err)
              }
          });
        } else if (res.cancel) {

        }
      }
    })
  },

  //商品跳转
  toGoods: function(e){
    let that = this;
    let collectid = e.currentTarget.dataset.name;
    wx.redirectTo({
      url: '/pages/goods/goods?cid='+collectid,
    })
  }

})